{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="float-end">
        <button type="button" data-bs-toggle="tooltip" title="{{ button_filter }}" onclick="$('#filter-recurring').toggleClass('d-none');" class="btn btn-light d-md-none"><i class="fas fa-filter"></i></button>
      </div>
      <h1>{{ heading_title }}</h1>
      <ol class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
          <li class="breadcrumb-item"><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ol>
    </div>
  </div>
  <div class="container-fluid">
    <div class="row">
      <div id="filter-recurring" class="col-lg-3 col-md-12 order-lg-last d-none d-lg-block mb-3">
        <div class="card">
          <div class="card-header"><i class="fas fa-filter"></i> {{ text_filter }}</div>
          <div class="card-body">
            <div class="mb-3">
              <label for="input-order-recurring-id" class="form-label">{{ entry_order_recurring_id }}</label>
              <input type="text" name="filter_order_recurring_id" value="{{ filter_order_recurring_id }}" placeholder="{{ entry_order_recurring_id }}" id="input-order-recurring-id" class="form-control"/>
            </div>
            <div class="mb-3">
              <label for="input-customer" class="form-label">{{ entry_customer }}</label>
              <input type="text" name="filter_customer" value="{{ filter_customer }}" placeholder="{{ entry_customer }}" id="input-customer" class="form-control"/>
            </div>
            <div class="mb-3">
              <label for="input-order-id" class="form-label">{{ entry_order_id }}</label>
              <input type="text" name="filter_order_recurring_id" value="{{ filter_order_recurring_id }}" placeholder="{{ entry_order_id }}" id="input-order-id" class="form-control"/>
            </div>
            <div class="mb-3">
              <label for="input-status" class="form-label">{{ entry_status }}</label> <select name="filter_status" id="input-status" class="form-select">
                {% for recurring_status in recurring_statuses %}
                  <option value="{{ recurring_status.value }}"{% if filter_status == recurring_status.value %} selected{% endif %}>{{ recurring_status.text }}</option>
                {% endfor %}
              </select>
            </div>
            <div class="mb-3">
              <label for="input-reference" class="form-label">{{ entry_reference }}</label>
              <input type="text" name="filter_reference" value="{{ filter_reference }}" placeholder="{{ entry_reference }}" id="input-reference" class="form-control"/>
            </div>
            <div class="mb-3">
              <label for="input-date-date_added" class="form-label">{{ entry_date_added }}</label>
              <div class="input-group date">
                <input type="text" name="filter_date_added" value="{{ filter_date_added }}" placeholder="{{ entry_date_added }}" id="input-date-date_added" class="form-control"/>
                <div class="input-group-text"><i class="fas fa-calendar"></i></div>
              </div>
            </div>
            <div class="text-end">
              <button type="button" id="button-filter" class="btn btn-light"><i class="fas fa-filter"></i> {{ button_filter }}</button>
            </div>
          </div>
        </div>
      </div>
      <div class="col-lg-9 col-md-12">
        <div class="card">
          <div class="card-header"><i class="fas fa-list"></i> {{ text_list }}</div>
          <div id="recurring" class="card-body">{{ list }}</div>
        </div>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
$('#recurring').on('click', 'thead a, .pagination a', function(e) {
    e.preventDefault();

    $('#recurring').load(this.href);
});

$('#button-filter').on('click', function() {
    url = '';

    var filter_order_recurring_id = $('#input-order-recurring-id').val();

    if (filter_order_recurring_id) {
        url += '&filter_order_recurring_id=' + encodeURIComponent(filter_order_recurring_id);
    }

    var filter_order_id = $('#input-order_id').val();

    if (filter_order_id) {
        url += '&filter_order_id=' + encodeURIComponent(filter_order_id);
    }

    var filter_reference = $('#input-reference').val();

    if (filter_reference) {
        url += '&filter_reference=' + encodeURIComponent(filter_reference);
    }

    var filter_customer = $('#input-customer').val();

    if (filter_customer) {
        url += '&filter_customer=' + encodeURIComponent(filter_customer);
    }

    var filter_status = $('#input-status').val();

    if (filter_status != 0) {
        url += '&filter_status=' + encodeURIComponent(filter_status);
    }

    var filter_date_added = $('#input-date_added').val();

    if (filter_date_added != '') {
        url += '&filter_date_added=' + encodeURIComponent(filter_date_added);
    }

    $('#recurring').load('index.php?route=sale/recurring|list&user_token={{ user_token }}' + url);
});

$('#form input').keydown(function(e) {
    if (e.keyCode == 13) {
        filter();
    }
});

$('.date').datetimepicker({
    'format': 'YYYY-MM-DD',
    'locale': '{{ datepicker }}',
    'allowInputToggle': true
});
//--></script>
<script type="text/javascript"><!--
$('#input-customer').autocomplete({
    'source': function(request, response) {
        $.ajax({
            url: 'index.php?route=customer/customer|autocomplete&user_token={{ user_token }}&filter_name=' + encodeURIComponent(request),
            dataType: 'json',
            success: function(json) {
                response($.map(json, function(item) {
                    return {
                        label: item['name'],
                        value: item['customer_id']
                    }
                }));
            }
        });
    },
    'select': function(item) {
        $('#input-customer').val(item['label']);
    }
});
//--></script>
{{ footer }}